package com.clickhouse_test.app.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 返回参数
 * @author Administrator
 *
 */
public class ResultSelectMsg {
	//返回数据
    private List<Map<String, String>> rows;
    //总条数
    private Integer totalRowCount = 0;
    //总页数
    private Integer pageCount = 0;
    //每页显示条数
    private Integer pageSize = 0;
    //是否成功
    private String success;
    //异常原因
    private String error;
    //返回数据
    private Map<Object, Object> resultMap;

    /**
     * 返回值
     * @return
     */
    public Map<Object, Object> getMsg(){
        Map<Object, Object> map = new HashMap<>();
        map.put("TotalRowCount",this.getTotalRowCount());
        if(this.getPageSize() <= 0){
        	this.setPageSize(10);
        }
        if(this.getTotalRowCount() <= 0){
        	this.setTotalRowCount(0);
        	this.setPageSize(10);
        	this.setPageCount(1);
        }else{
            if(this.getTotalRowCount() % this.getPageSize() == 0){
            	map.put("PageCount",this.getTotalRowCount()  / this.getPageSize());
            }else{
            	map.put("PageCount",this.getTotalRowCount()  / this.getPageSize() + 1);
            }
        }

        //map.put("PageCount",this.getPageCount());
        map.put("Rows",this.getRows());
        List<Map<Object, Object>> msg = new ArrayList<>();
        msg.add(map);
        Map<Object, Object> resoutMap = new HashMap<>();
        resoutMap.put("msg",msg);
        return resoutMap;
    }

    /**
     * 修改方法的返回值
     * @return
     */
    public Map<Object, Object> getUpdateMsg(){
        Map<Object, Object> map = new HashMap<>();
        map.put("success",this.getSuccess());
        List<Map<Object, Object>> msg = new ArrayList<>();
        msg.add(map);
        Map<Object, Object> resoutMap = new HashMap<>();
        resoutMap.put("msg",msg);
        return resoutMap;
    }
    
    
    /**
     * 修改方法的返回值
     * 增加了异常原因
     * @return
     */
    public Map<Object, Object> getUpdateMsg01(){
        Map<Object, Object> map = new HashMap<>();
        map.put("success",this.getSuccess());
        map.put("error", this.error);
        List<Map<Object, Object>> msg = new ArrayList<>();
        msg.add(map);
        Map<Object, Object> resoutMap = new HashMap<>();
        resoutMap.put("msg",msg);
        return resoutMap;
    }


    /**
     * 有参数的返回值
     * @param totalRowCount  数据总量
     * @param pageCount 总页数
     * @param rows 当前查询数据
     * @return
     */
    public Map<Object, Object> getMsg(Integer totalRowCount,Integer pageCount,List<Map<String, String>> rows){
        this.setTotalRowCount(totalRowCount);
        this.setPageCount(pageCount);
        this.setRows(rows);
        return getMsg();
    }

    public List<Map<String, String>> getRows() {
        return rows;
    }

    public void setRows(List<Map<String, String>> rows) {
        this.rows = rows;
    }

    public Integer getTotalRowCount() {
        return totalRowCount;
    }

    public void setTotalRowCount(Integer totalRowCount) {
        this.totalRowCount = totalRowCount;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public String getSuccess() {
        return success;
    }

    public void setSuccess(String success) {
        this.success = success;
    }

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public Map<Object, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<Object, Object> resultMap) {
		this.resultMap = resultMap;
	}
	

}
